import {Store} from 'iflux2';
import {message} from 'antd';

import RegisterLogin from './actor/register-login';
import {getRegLogSetup, saveRegLogSetup} from './webapi';

export default class AppStore extends Store{
  bindActor() {
    return [
      new RegisterLogin
    ]
  }
  init =async () => {
    const {data, err} = await getRegLogSetup();
    this.dispatch('register-login-init', data)
  }
  onSetting = (data) => {
    this.dispatch('handle-setup', data);
  }
  onSave =async () =>{
    let {username_reg, username_mobile_reg, ...rest} = this.state().toJS();
    let params = {username_reg, username_mobile_reg: username_reg == 1 ? 0 : 1, ...rest};
    const {err} = await saveRegLogSetup(params);
    if(!err) {
      message.success('保存成功')
    }
  }
}